package model

import (
	"context"
	"github.com/Masterminds/squirrel"
	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ UmsAdminLoginLogModel = (*customUmsAdminLoginLogModel)(nil)

type (
	// UmsAdminLoginLogModel is an interface to be customized, add more methods here,
	// and implement the added methods in customUmsAdminLoginLogModel.
	UmsAdminLoginLogModel interface {
		umsAdminLoginLogModel
		Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error
		RowBuilder() squirrel.SelectBuilder
		CountBuilder(field string) squirrel.SelectBuilder
	}

	customUmsAdminLoginLogModel struct {
		*defaultUmsAdminLoginLogModel
	}
)

// NewUmsAdminLoginLogModel returns a model for the database table.
func NewUmsAdminLoginLogModel(conn sqlx.SqlConn, c cache.CacheConf) UmsAdminLoginLogModel {
	return &customUmsAdminLoginLogModel{
		defaultUmsAdminLoginLogModel: newUmsAdminLoginLogModel(conn, c),
	}
}

// export logic
func (m *defaultUmsAdminLoginLogModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
	return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
		return fn(ctx, session)
	})

}

// export logic
func (m *defaultUmsAdminLoginLogModel) RowBuilder() squirrel.SelectBuilder {
	return squirrel.Select(umsAdminLoginLogRows).From(m.table)
}

// export logic
func (m *defaultUmsAdminLoginLogModel) CountBuilder(field string) squirrel.SelectBuilder {
	return squirrel.Select("COUNT(" + field + ")").From(m.table)
}

// export logic
func (m *defaultUmsAdminLoginLogModel) SumBuilder(field string) squirrel.SelectBuilder {
	return squirrel.Select("IFNULL(SUM(" + field + "),0)").From(m.table)
}
